import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class Baxterpump {
	private
		double conc;
		double rate;
		double vol;
		double dose;
		double volume;
		double drugamount;
		double dilutent;
		Units u;
		int m;
		static int next_pres = 1;
		
		public static class Mode {
			public static final int VR = 1;
			public static final int VT = 2;
			public static final int PI = 3;
			public static final int PB = 4;	
			public static List<Integer> Modes = Arrays.asList(VR, VT, PI, PB);
		}
		
		UserSimulator user;
	public
		Baxterpump(UserSimulator u) {
			user = u;
		}
		boolean run() {
			m = user.getMode();
			if (m == Mode.VR) {
				return volumerate();
			
			} else if (m == Mode.VT) {
				return volumetime();
				
			} else if (m == Mode.PI) {
				return patientindependant();
				
			} else {
				return patientweight();		
			}
		}
	
		boolean volumerate() {
			return true;
		}
		
		boolean volumetime() {
			return true;			
		}
		
		boolean patientindependant() {
			return true;			
		}
		
		boolean patientweight() {
			u = user.getUnits();
			if(u == null) {
				return false;
			}
			conc = user.getConc();
			if(conc == -1) {
				return false;
			}
			drugamount = user.get_drug_amount();
			if(drugamount == -1) {
				return false;
			}
			dilutent = user.get_dilutent_volume();
			if(dilutent == -1) {
				return false;
			}
			dose = user.getDose();
			if(dose == -1) {
				return false;
			}
			volume = user.getVolume();
			if(volume == -1) {
				return false;
			}
			return true;
		}
				
		boolean gen_pres() {
			
			// must check for valid values here
			if (m == Mode.PI) {
				//rate must be computed, rate = dose/conc
				rate = dose*u.Dunits_tomcghr()/(conc * u.Cunit_tomcg());
			}
			else if (m == Mode.PB) {
				
			}
			else if (m == Mode.VT){
				
			}
			try {
			    BufferedWriter out = new BufferedWriter(new FileWriter("prescription" + next_pres));
			    out.write("Volume: " + volume);
			    out.write("Rate: " + rate);    
			    out.write("Conc: " + conc);
			    out.close();
			    next_pres++;
			    return true;
			} catch (IOException e) {
			}
			return false;
		}

}
